<template>
  <div ref="lazyItem" class="lazy-item">
    <slot v-if="show"></slot>
  </div>
</template>

<script>
export default {
  data() {
    return {
      show: false,
      observe: null,
    };
  },
  methods: {
    init() {
      this.observe = new IntersectionObserver((changes, observer) => {
        if (changes[0].isIntersecting) {
          this.show = true;
        }
      });
      this.observe.observe(this.$el);
    },
  },
  mounted() {
    this.init();
  },
};
</script>

<style lang="less" scoped>
.lazy-item {
  width: 100%;
  height: 100%;
}
</style>
